import { calcTotal } from "../../../../common/util/calcUtils";
import { CARD } from "../../constant";

/**
* @description: 表体编辑后事件
* @param: moduleId 区域编码
* @param: key 当前字段编码
*/
export function afterTableEvent(props, moduleId, key, value, changedrows, index, record, type, method) {
    if('money' == key ||'tax'==key){
        let head_keys = [];
        let body_keys = ['money', 'tax'];
        let value = calcTotal(props, CARD.form_id, head_keys, CARD.table_code, body_keys);
        props.form.setFormItemsValue(CARD.form_id, { 'count': { value: value} });
    }
}

export function setBodyRequired(props, index) {
    let meta = props.meta.getMeta();
        let value = props.cardTable.getValByKeyAndIndex(CARD.table_code, index, 'cutsup');
        if(value.value == ''){
            meta[CARD.table_code] && meta[CARD.table_code].items.map((item) => {
                if(item.attrcode == 'bdef2'){
                    item.required = false
                }
            })
        }else{
            meta[CARD.table_code] && meta[CARD.table_code].items.map((item) => {
                if(item.attrcode == 'bdef2'){
                    item.required = true
                }
            })
        }
        props.meta.setMeta(meta);
}